async function retryOperation(operation, maxRetries = 5) {
    try {
        for (let attempt = 1; attempt <= maxRetries; attempt++) {
            try {
                return await operation();
            } catch (error) {
                if (attempt === maxRetries) {
                    throw error;
                }

                // Calculate delay based on attempt number
                let minDelay, maxDelay;
                if (attempt <= 2) {
                    // First two retries: 3-5 seconds
                    minDelay = 3000;
                    maxDelay = 5000;
                } else {
                    // Last three retries: 4-8 seconds
                    minDelay = 4000;
                    maxDelay = 8000;
                }

                const delay = minDelay + Math.random() * (maxDelay - minDelay);
                console.log(`Retry attempt ${attempt} of ${maxRetries}. Waiting ${Math.round(delay/1000)}s...`);
                await new Promise(resolve => setTimeout(resolve, delay));
            }
        }
    } catch (error) {
        reportError(error);
        throw error;
    }
}
